import { useEffect, useState } from "react";
import { LocalStorageKeyNameSpace } from "../config/local-storage-key";

/**
 * 菜单栏切换、展开事件
 * @returns 
 */
const useSlideCollapsed = () => {
  const { slideMenuCollapsed } = LocalStorageKeyNameSpace;
  const [collapsed, setCollapsed] = useState<boolean>();
  useEffect(() => {
    const val = localStorage.getItem(slideMenuCollapsed) === 'true';
    setCollapsed(val);
  }, []);

  /**
   * 切换状态
   */
  const change = () => {
    setCollapsed(!collapsed);
  };

  return {
    collapsed,
    setCollapsed: change
  };
};

export { useSlideCollapsed };
